package j_util.sorters;

import j_util.comparators.StringComparator;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class BubbleSort extends Sort {

    public String getName() {
        return "BubbleSort";
    }

    public <T> void sort(List<T> list, Comparator<T> comparator) {
        int left = 0;
        int right = list.size() - 1;
        sort(list, left, right, comparator);
    }

    public <T> void sort(List<T> list, int left, int right, Comparator<T> c) {
        resetVariables();
        time = System.currentTimeMillis();
        for (int i = left; i < right; i++) {
            for (int j = right; j > i; j--) {
                compareAndExchange(list, j - 1, j, c);
            }
        }
        time = System.currentTimeMillis() - time;
    }

    public static void main(String[] args) {
        BubbleSort bubbleSort = new BubbleSort();
        String[] callesAcostadas = {"Azopardo", "Paseo Colon", "Balcarce", "Defensa", "Bolivar", "Peru", "Chacabuco",
                "Piedras", "Tacuari", "Bernardo de Irigoyen"};
        String[] callesParadas = {"Avenida Brasil", "Avenida Juan de Garay", "Cochabamba", "Avenida San Juan",
                "Humberto 1", "Carlos Calvo", "Estados Unidos", "Avenida Independencia", "Chile", "Mexico"};
        List<String> calles = new ArrayList<String>();
        for (int j = 0; j < callesAcostadas.length; j++) {
            calles.add(callesAcostadas[j]);
        }
        for (int j = 0; j < callesParadas.length; j++) {
            calles.add(callesParadas[j]);
        }
        bubbleSort.sort(calles, new StringComparator());
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.print("{");
        for (int j = 0; j < calles.size(); j++) {
            System.out.print("\"" + calles.get(j) + "\",");
        }
        System.out.print("}");
    }
}
